home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / objtools / tlline.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  205 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    tlline -
  19.  *        Locate interesting edges in a set of triangles.
  20.  *
  21.  *    Positive Z's are closer than Negative Z's.
  22.  *
  23.  *    uses special functions:
  24.  *        trinormal
  25.  *        vplane
  26.  *        flerp
  27.  *        vlerp
  28.  *        vdot
  29.  *
  30.  *            Paul Haeberli - 1990
  31.  */
  32. #include "stdio.h"
  33. #include "gl.h"
  34. #include "device.h"
  35. #include "vect.h"
  36.  
  37. float frand();
  38.  
  39. #define WSIZE        (300)
  40. #define ASPECT        (3.0/2.0)
  41. FILE *outf;
  42.  
  43. float myw;
  44.  
  45. /* 
  46.  *    GL output funcs 
  47.  *
  48.  */
  49. int widthline(w)
  50. float w;
  51. {
  52.     myw = w;
  53. }
  54.  
  55. int drawline(p0,p1)
  56. vect *p0, *p1;
  57. {
  58.     int iw;
  59.  
  60.     iw = myw*400.0+frand();
  61.     if(iw<1)
  62.        iw = 1;
  63.     linewidth(iw);
  64.     bgnline();
  65.     v2f((float*)p0);
  66.     v2f((float*)p1);
  67.     endline();
  68. }
  69.  
  70. /* 
  71.  *    PostScript output funcs 
  72.  *
  73.  */
  74. int widthpsline(w)
  75. float w;
  76. {
  77.     pslinewidth(w);
  78. }
  79.  
  80. int drawpsline(p0,p1)
  81. vect *p0, *p1;
  82. {
  83.     psline(outf,p0,p1);
  84. }
  85.  
  86. /* 
  87.  *    Both output funcs 
  88.  *
  89.  */
  90. int widthbothline(w)
  91. float w;
  92. {
  93.     widthline(w);
  94.     widthpsline(w);
  95. }
  96.  
  97. int drawbothline(p0,p1)
  98. vect *p0, *p1;
  99. {
  100.     drawline(p0,p1);
  101.     drawpsline(p0,p1);
  102. }
  103.  
  104. float frand2()
  105. {
  106.     float v;
  107.  
  108.     v = frand();
  109.     return v*v;
  110. }
  111.  
  112. randsel()
  113. {
  114.     float hf, sil, w, seg;
  115.  
  116.     hf = 30.0*frand();
  117.     handsetwobble(hf,0.005*frand());
  118.     seg = 1.0/(2.0*hf);
  119.     handsetseglen(seg);
  120.     handsetdropout(0.1*frand());
  121.     hiddencolorthresh(0.3*frand());
  122.     sil = 0.03*frand2();
  123.     hiddensilwidth(sil/3.0,sil);
  124.     hiddenhalowidth(0.03*frand2());
  125.     w = 0.03*frand2();
  126.     hiddenfacewidths(w/3.0,w,w/2.0);
  127.     if(frand()>0.25)
  128.         hiddenextend(0.10*frand(),0.10*frand(),frand());
  129.     else
  130.         hiddenextend(0.0,0.0,0.0);
  131. }
  132.  
  133. openps(name)
  134. char *name;
  135. {
  136. /* open output PostScript file */
  137.     outf = fopen(name,"w");
  138.     if(!outf) {
  139.     fprintf(stderr,"tlline: can't open output file\n");
  140.     exit(1);
  141.     }
  142.     beginps(outf,3.0/2.0,-ASPECT,ASPECT,-1.0,1.0);
  143. }
  144.  
  145. closeps()
  146. {
  147.     endps();
  148.     fclose(outf);
  149. }
  150.  
  151. main(argc,argv)
  152. int argc;
  153. char **argv;
  154. {
  155.     int i;
  156.  
  157.     if(argc<3) {
  158.     fprintf(stderr,"usage: tlline input.tl out.ps [-g]\n");
  159.     exit(1);
  160.     }
  161. /* set up the parameters */
  162.  
  163.     handsetwobble(50.0,0.0);
  164.     handsetwarp(1.0,0.0);
  165.     handsetdropout(0.0);
  166.     handsetseglen(0.1);
  167.  
  168.     hiddencolorthresh(0.10);
  169.     hiddensilwidth(0.001,0.003);
  170.     hiddenhalowidth(0.003);
  171.     hiddenfacewidths(0.003,0.006,0.003);
  172.     hiddenextend(0.0,0.0,0.0);
  173.  
  174.     if(argc>3) {
  175.     prefposition(0,(3*WSIZE)-1,50,50+(2*WSIZE)-1);
  176.     foreground();
  177.     winopen("tlline");
  178.     qdevice(LEFTMOUSE);
  179.     qdevice(MIDDLEMOUSE);
  180.     RGBmode();
  181.     gconfig();
  182.     deflinestyle(1,0x3030);
  183.  
  184.     reshapeviewport();
  185.     ortho(-ASPECT,ASPECT,-1.0,1.0,-2.0,2.0);
  186.     rgb(1.0,1.0,1.0);
  187.     clear();
  188.     rgb(0.0,0.0,0.0);
  189.  
  190. /* make the hidden line picture */
  191.  
  192.     openps(argv[2]);
  193.     hiddenline(argv[1],drawbothline,widthbothline);
  194.     closeps();
  195.     } else {
  196. /* make the hidden line picture */
  197.     openps(argv[2]);
  198.     hiddenline(argv[1],drawpsline,widthpsline);
  199.     closeps();
  200.     }
  201.  
  202. /* close the output file */
  203.     exit(0);
  204. }
  205.